package com.gongj.constant;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class StaticValue implements InitializingBean{

    public static String APP_ID;
    public static String APP_USER;

//    @Value("${channl.ali.appId}")
//    public void setAppId(String appId) {
//        APP_ID = appId;
//    }
//
//    @Value("${channl.ali.appUser}")
//    public void setAppUser(String appUser) {
//        APP_USER = appUser;
//    }


    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("afterPropertiesSet 初始化方法执行");
//        //APP_ID = environment.getProperty("channl.ali.appId");
//       // APP_USER = environment.getProperty("channl.ali.appUser");
        APP_ID = appId;
        APP_USER = appUser;
    }




    @Value("${channl.ali.appId}")
    private String appId;
    @Value("${channl.ali.appUser}")
    private String appUser;
//    @Autowired
    private Environment environment;

    public StaticValue() {
        System.out.println("构造方法执行 = " + environment);
    }

    @Autowired
    private void setq(Environment environment){
        System.out.println("依赖注入方法执行 = " + environment);
        this.environment = environment;
    }
    @PostConstruct
    public void init(){
        System.out.println("PostConstruct 标注的init方法执行");
        //APP_ID = environment.getProperty("channl.ali.appId");
        //APP_USER = environment.getProperty("channl.ali.appUser");
        //APP_ID = appId;
        //APP_USER = appUser;
    }
}
